package zheezes.protocol.impl.gbw.afn8d;

import java.util.ArrayList;
import java.util.List;

import zheezes.protocol.impl.gbw.bean.VipFrozenDataParam;
import zheezes.protocol.impl.gbw.format.DataForm34;


public class Afn8DDownF2S0DataUnit extends Afn8DDownF2DataUnit {
	private DataForm34 type = new DataForm34();
	private List<VipFrozenDataParam> params = new ArrayList<VipFrozenDataParam>();
	
	public int addParam(VipFrozenDataParam param) {
		assert params.size() == type.getAmount();
		while (params.size() < 128) {
			params.add(param);
			type.setAmount(type.getAmount() + 1);
			return 0;
		}
		return -1;
	}

	@Override
	public int sizeOfData() {
		int size = 1;
		for (VipFrozenDataParam data : params) {
			size += data.sizeof();
		}
		return size;
	}

	@Override
	public int getData(byte[] buf, int offset) {
		int idx = offset;
		idx += type.getBytes(buf, idx);
		for (VipFrozenDataParam param : params) {
			idx += param.getBytes(buf, idx);
		}
		return idx - offset;
	}

	@Override
	public int setData(byte[] buf, int offset, int max) {
		int idx = offset;
		idx += type.setBytes(buf, idx);
		for (VipFrozenDataParam data : params) {
			idx += data.setBytes(buf, idx);
		}
		return idx - offset;
	}
}
